package com.framework.base.taglib.ui; 

import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import com.framework.base.taglib.ui.common.PowerTag;
import com.framework.base.util.StringUtil;

/**
 * Description:用于输出button标签
 * tabaleName(对应的表名):
 * Company: framework
 * @author：www.51wuxia.com
 * @version 1.0
 */
@SuppressWarnings("serial")
public class ButtonTag extends PowerTag{
	private String id="";
	private String name="";
	private String value="";
	private String style="";
	private String styleClass="";
	private String onclick="";
	private String operation="";//用于控制权限 书定格式为ModuleID.OperationType
	private boolean display=false;//如果没权限时 true代表变灰 false代表不显示	private String type="button";//按钮类型 默认为按钮
	@Override
	public int doStartTag() throws JspException {
		return super.doStartTag();
	}
	@SuppressWarnings("unchecked")
	@Override
	public int doEndTag() throws JspException {
		JspWriter out = pageContext.getOut();
		ResourceBundle v = ResourceBundle.getBundle("globalMessages", Locale.getDefault());	
		StringBuffer contentsb=new StringBuffer("<input type=\""+getType()+"\" ");
		contentsb.append(StringUtil.isNullorEmpty(getId())?"":"id=\""+getId()+"\" ");
		contentsb.append(StringUtil.isNullorEmpty(getName())?"":"name=\""+getName()+"\" ");
		try {
			contentsb.append(StringUtil.isNullorEmpty(getValue())?"":"value=\""+v.getString(getValue())+"\" ");
		} catch (Exception e) {
			contentsb.append(StringUtil.isNullorEmpty(getValue())?"":"value=\""+getValue()+"\" ");
		}
		contentsb.append(StringUtil.isNullorEmpty(getStyle())?"":"style=\""+getStyle()+"\" ");
		contentsb.append(StringUtil.isNullorEmpty(getStyleClass())?"":"class=\""+getStyleClass()+"\" ");
		contentsb.append(StringUtil.isNullorEmpty(getOnclick())?"":"onclick=\""+getOnclick()+"\" ");
		
		boolean canOperation=doJudgePower(getOperation());
		try {
			if(canOperation){
				out.print(contentsb.toString()+"/>");
			}else{
				if(display){
					contentsb.append("disabled=\"disabled\" ");
					out.print(contentsb.toString()+"/>");
				}
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.doEndTag();
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getStyle() {
		return style;
	}
	public void setStyle(String style) {
		this.style = style;
	}
	public String getStyleClass() {
		return styleClass;
	}
	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}
	public String getOnclick() {
		return onclick;
	}
	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}
	
	public String getOperation() {
		return operation;
	}
	public void setOperation(String operation) {
		this.operation = operation;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public boolean isDisplay() {
		return display;
	}
	public void setDisplay(boolean display) {
		this.display = display;
	}
	
}
